//
//  PushMoreTableViewCell.m
//  Movie
//
//  Created by cjy on 16/3/30.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "PushMoreTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "MovieModel.h"

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
@implementation PushMoreTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        self.clipsToBounds = YES;
        
        _imglink= [[UIImageView alloc]initWithFrame:CGRectMake(0, -(kHeight/1.7 -240)/2, kWidth, kHeight/1.7)];
        
        _imglink.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView  addSubview:_imglink];
        
        
        
        _coverview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 240)];
        _coverview.backgroundColor = [UIColor colorWithWhite:0 alpha:0.33];
        [self.contentView addSubview:_coverview];
        
        _title = [[UILabel alloc]initWithFrame:CGRectMake(0, 240 / 2 - 30, kWidth, 30)];
        
        _title.font = [UIFont boldSystemFontOfSize:16];
        
        _title.textAlignment = NSTextAlignmentCenter;
        
        _title.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_title];
        
        _littleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 240 / 2 + 30, kWidth, 30)];
        
        _littleLabel.font = [UIFont systemFontOfSize:14];
        
        _littleLabel.textAlignment = NSTextAlignmentCenter;
        
        _littleLabel.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_littleLabel];
        
        
    }
    return self;
}



- (void)passModel:(MovieModel *)model{
    
    [self.imglink sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail] placeholderImage:[UIImage imageNamed:@"zwt"]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.imglink.contentMode = UIViewContentModeScaleAspectFill;
    }];
    
    self.title.text = model.title;
    self.title.textAlignment = NSTextAlignmentCenter;
    self.title.textColor = [UIColor whiteColor];
    
    
    
    
    // 转换时间
    NSInteger time = model.duration;
    
    NSString *timeString = [NSString stringWithFormat:@"%02ld'%02ld''",time/60,time% 60];//显示的是音乐的总时间
    
    NSString *string = [NSString stringWithFormat:@"#%@ / %@",model.category, timeString];
    
    _littleLabel.text = string;

    
}

- (CGFloat)cellOffset {
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
    CGFloat offset =  -offsetDig * (kHeight/1.7 - 250)/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    
    
    
    self.imglink.transform = transY;
    
    return offset;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
